import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:situation/data/request/intell_request.dart';
import 'package:situation/domain/user/task.dart';
import 'package:situation/widgets/app/app_task_card.dart';
import 'package:situation/widgets/mk_empty.dart';

class TaskListItem extends StatefulWidget {
  final int status;

  const TaskListItem({super.key, required this.status});

  @override
  State<TaskListItem> createState() => _TaskListItemState();
}

class _TaskListItemState extends State<TaskListItem> {
  int current = 1;
  int size = 10;

  List<Task> dataList = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }

  getData() async {
    dataList.addAll(
      await IntellRequest.getMyTaskList(current, size, widget.status),
    );
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return EasyRefresh(
      onRefresh: () async {
        current = 1;
        dataList = [];
        getData();
      },
      onLoad: () async {
        current++;
        getData();
      },
      child: dataList.length > 0 ?ListView.builder(
        itemCount: dataList.length,
        itemBuilder: (context, index) {
          return  AppTaskCard(task: dataList[index]);
        },
      ) : MkEmpty(),
    );
  }
}
